package com.yansu.cloud.feign;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.yansu.cloud.bean.User;

import feign.hystrix.FallbackFactory;

/**
 * 
 * @author 言肃
 * @email yansu_code@126.com
 * @version 1.0
 * @date Aug 3, 2018 6:46:19 PM
 */
@Component
public class UserHystrixFallBackFactory implements FallbackFactory<UserFeignClient> {

	private static final Logger LOGGER = LoggerFactory.getLogger(UserHystrixFallBackFactory.class);

	@Override
	public UserFeignClient create(Throwable cause) {
		LOGGER.info("fackback; the reason was: " + cause.getMessage());

		return new UserFeignClientWithFallBackFactory() {
			@Override
			public User findById(Long id) {
				User user = new User();
				user.setId(-1L);
				return user;
			}
		};
	}

}
